Repository navigation
feat: Accept synchronous hooks on the async client - #548
Merged
Merged
Conversation
AsyncLDClient now takes the same ldclient.hook.Hook as LDClient, so integrations such as the OpenTelemetry tracing hook work with it. The hook stages run synchronously in the caller's task, so a span made current in the before stage stays current until the after stage. AsyncHook is removed. AsyncPlugin keeps its async register(), and its get_hooks() returns Hook instances. AsyncConfig now raises TypeError for a hook that is not a Hook or a plugin that is not an AsyncPlugin, which matches add_hook().
Match the sync client: AsyncConfig and add_hook() ignore items of the wrong type. The async contract-test service uses the sync PostingHook. Remove redundant docstring notes.
The after stages get an error detail with the default value, and the exception is re-raised. A hook such as the OpenTelemetry tracing hook can then detach its context and end its span.
jsonbailey
force-pushed
the
jb/sdk-3077/sync-hooks-async-client
branch
from
November 2, 2026 14:24
915b8d6 to
17e8352
Compare
jsonbailey
marked this pull request as ready for review
November 2, 2026 15:06
keelerm84
approved these changes
Nov 2, 2026
jsonbailey
added a commit
that referenced
this pull request
Nov 2, 2026
🤖 I have created a release *beep* *boop* --- ## [9.19.0](9.18.4...9.19.0) (2026-11-02) ### Breaking changes to the experimental async client The async client is experimental, so these changes do not cause a major version bump. If you use `AsyncLDClient` with hooks or plugins, update your code: * Remove the experimental `AsyncHook` class. The async client now uses the same synchronous `Hook` class as the sync client. Change each `AsyncHook` subclass to subclass `Hook`, and change its `async def` stages to `def`. The stages run on the event loop, so they must not block. ([#548](#548)) ([2457311](2457311)) * `AsyncPlugin.get_hooks` now returns a list of `Hook` instances. `AsyncPlugin.register` stays async. ([#548](#548)) ([2457311](2457311)) ### Features * Accept synchronous hooks on the async client ([#548](#548)) ([2457311](2457311)) ### Bug Fixes * Run after-evaluation hooks when an async evaluation is cancelled or raises ([2457311](2457311)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > **Release 9.19.0** — bumps the package version from **9.18.4** to **9.19.0** in `pyproject.toml`, `ldclient/version.py`, `.release-please-manifest.json`, and the provenance verification example in `PROVENANCE.md`, and adds the **9.19.0** section to `CHANGELOG.md`. > > What ships in this release (documented in the new changelog entry, not in this diff’s code): > > The **experimental async client** unifies on the sync **`Hook`** API: **`AsyncHook` is removed**, **`AsyncPlugin.get_hooks`** returns **`Hook`** instances ( **`AsyncPlugin.register`** stays async), and the async client **accepts synchronous hooks**. Hook stage methods should be plain **`def`** (non-blocking on the event loop). A bug fix ensures **after-evaluation hooks run** when an async evaluation is **cancelled or raises**. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 54a6f6a. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: jsonbailey <jbailey@launchdarkly.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: Remove the experimental AsyncHook class
Warning
Breaking change to the experimental async API. Code that subclasses
AsyncHookor passesAsyncHookinstances toAsyncLDClientmust change to useldclient.hook.Hook. The async API is experimental, so this is not marked with!and does not need a major version. Edit the release notes to call out the break for async users.Summary
AsyncLDClientnow uses the sameldclient.hook.HookasLDClient, so existing integrations such as the OpenTelemetry tracing hook work with the async client. Before this change, the async client accepted onlyAsyncHookand ignored sync hooks.AsyncHookis removed. The async API is experimental.AsyncPluginkeeps its asyncregister(). Itsget_hooks()now returnsHookinstances.AsyncConfigandadd_hook()ignore items of the wrong type, the same as the sync client.PostingHook.Note
Overview
Breaking change for the experimental async client:
AsyncHookis removed.AsyncLDClientandAsyncConfignow take the sameHooktype asLDClient, so shared integrations (e.g. OpenTelemetry) work without a separate async hook API.Hook before/after stages run synchronously in the caller’s task (not awaited). Context set in
before_evaluationstays visible through the evaluation and is cleared inafter_evaluation, which matters forcontextvarsand tracing under concurrentvariation()calls.When evaluation raises or is cancelled, after hooks still run with an error
EvaluationDetail(default value +EXCEPTIONreason) before the exception propagates, so hooks can tear down spans/context.add_hook()and confighooksfiltering match the sync client (ignore non-Hooktypes instead of raising on sync hooks).AsyncPlugin.get_hooks()returnsHookinstances; contract tests dropAsyncPostingHookand registerPostingHookvia config.Reviewed by Cursor Bugbot for commit 17e8352. Bugbot is set up for automated code reviews on this repo. Configure here.